package tools

import (
	"io"
	"net/http"
)

func DownloadImage(u, targetType string) (bs []byte, err error) {
	client := &http.Client{}

	req, err := http.NewRequest("GET", u, nil)
	if err != nil {
		return nil, err
	}

	switch targetType {
	case "png":
		req.Header.Set("Accept", "image/png")

	}
	resp, err := client.Do(req)
	if err != nil {
		return nil, err
	}

	bs, err = io.ReadAll(resp.Body)
	resp.Body.Close()
	if err != nil {
		return nil, err
	} else {
		return bs, nil
	}
}
